package com.androidhuman.example.ToastExample;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

public class ToastExampleActivity extends Activity 
								  implements OnCheckedChangeListener {
	private int LENGTH_TO_SHOW = Toast.LENGTH_SHORT;
	private EditText textShow;
	private RadioGroup radioGroup;
	private Button showToastButton; 
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        textShow = (EditText)findViewById(R.id.TextInput);
        
        showToastButton = (Button)findViewById(R.id.ShowToast);
        showToastButton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(ToastExampleActivity.this, textShow.getText().toString(), LENGTH_TO_SHOW)
				.show();
			}
		});
        
        
        radioGroup = (RadioGroup)findViewById(R.id.radioGroup);
        radioGroup.setOnCheckedChangeListener(this);
    }
    
	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		// TODO Auto-generated method stub
		switch(checkedId){
		case R.id.radio_long:
		LENGTH_TO_SHOW = Toast.LENGTH_LONG;
		break;
		case R.id.radio_short:
			LENGTH_TO_SHOW = Toast.LENGTH_SHORT;
		break;
		}
		
	}
}